package com.rme.common.core.exception;

/**
 * @author 周益和
 * @ClassName GlobalExceptionHandler
 * @qq 1552951165
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局捕获异常
 */
@Slf4j
// 项目在整合是 启动类 需要放入到 com.rme包 否则GlobalExceptionHandler无法被spring加载 全局捕获异常失效;
@ControllerAdvice(basePackages = "com.rme")
public class GlobalExceptionHandler {
    
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String, Object> errorResult(Exception e) {
        log.error("<error{}>", e);
        Map<String, Object> errorResultMap = new HashMap<String, Object>();
        errorResultMap.put("code", "500");
        errorResultMap.put("msg", "系统出现错误!");
        return errorResultMap;
    }
}